{include file="public/header"}
<div class="pub_wid notice_cont">
    <div class="notice_left bgb lf" id="enterPriseList">
        <h1>企业库<span>当前位置：<a href="/">主页</a>><a href="/index/enterprise/index">企业库</a></span></h1>
        <ul class="widthauto notice_select">
            <li>分类：
                <select v-model="trade_id" @change="changeTradeGetList()">
                    <option value="">=行业大类=</option>
                    <option v-for="item in tradeList" :value="item.id" >{{item.name}}</option>
                </select>
            </li>
            <li>
                <select v-model="tradeChildName" @change="changeWhereGetList()">
                    <option value="">=行业小类=</option>
                    <option v-for="item in tradeChildList" :value="item.name">{{item.name}}</option>
                </select>
            </li>
            <div id="distpicker">
            <li>省份：
                <select v-model="province" @change="changeAddress()">
                    <option>=全部=</option>
                </select>
            </li>
            <li>城市：
                <select v-model="city" @change="getList()">
                    <option>=全部=</option>
                </select>
            </li>
            </div>
        </ul>
        <div class="widthauto notice_select">
            <input v-model="enterpriseName"  placeholder="搜索企业"/>
            <button @click="getList()">搜索</button>
        </div>
        <div class="ent_cont widthauto">
            <dl v-for="(item,index) in list">
                <a :href="'/index/enterprise/detail/id/'+item.id">
                    <dt><img style="width: 148px;height: 75px" :src="item.logo" /></dt>
                    <dd><span>{{item.name}}</span>
                        <em v-if="item.member_category == 2&&item.member_grade!=2">[物流企业]</em>
                        <i v-if="item.member_category == 2&&item.member_grade==2">[VIP物流企业]</i>
                        <b v-if="item.member_category == 1">[货主企业]</b>
                    </dd>
                    <dd>{{item.company_info}}</dd>
                </a>
            </dl>
        </div>
        <div class="widthauto pages_box">
            <a @click="pageNumGetList(1)">首页</a>
            <a @click="pageNextList(-1)">上一页</a>
            <a v-for="(item,index) in pageInfo.total" :class="(index+1)==current_page?'pages_box_cur':''" @click="pageNumGetList(item)">{{item}}</a>
            <a @click="pageNextList(1)">下一页</a>
            <a  @click="pageNumGetList(pageInfo.total)">尾页</a>
        </div>
    </div>
    {include file="public/right"}
</div>
{include file="public/footer"}
<!--全国省份-->
<script src="/static/util/distpicker/distpicker.min.js"></script>
<script>
    var enterPriseListVm = new Vue({
        el:'#enterPriseList',
        data:{
            current_page:'1',//当前页
            num:'10',//每页显示几条
            serviceList:[],
            tradeList:[],
            trade_id:'',
            trade_name:'',
            tradeChildList:[],
            tradeChildName:'',
            province:'',
            city:'',
            pageInfo:{},
            enterpriseName:'',
            list:[]
        },
        computed:{
            address:function () {
                return this.province+this.city
            }
        },
        methods:{
            changeAddress:function(){
                this.city = ''
                this.getList();
                console.log(this.address)
            },
            getTradeList:function(){
                var el = this
                AjaxPostFree('/index/trade/getTradeList').then((response)=>{
                    el.tradeList = response.result
                })
            },
            getTradeChildList:function(){
                var el = this
                if(el.trade_id != ''){
                    var postData = {
                        "trade_id":el.trade_id
                    }
                    AjaxPost(postData,'/index/trade/getTradeChildByWhere').then((response=>{
                        el.tradeChildList = response.result
                    }))
                }

            },
            //联动调取分类
            changeTradeGetList:function(){
                var el = this
                el.current_page = 1
                el.tradeChildName=''
                el.getList()
                el.getTradeChildList()
            },
            pageNumGetList:function(page){
                var el = this
                el.current_page = page
                el.getList()
            },
            pageNextList:function (num) {
                var el = this;
                var set_current_page = el.current_page*1+num
                console.log(el.current_page)
                if( set_current_page < 1){
                    $.customToastr("error","已经是第一页啦");
                    return;
                }
                if(set_current_page > el.pageInfo.total){
                    $.customToastr("error","已经是最后一页啦");
                    return;
                }
                el.current_page = set_current_page
                el.getList();
            },
            //条件更改无法从第一页查询，跳转方法
            changeWhereGetList:function(){
                var el = this
                el.current_page = 1
                el.getList()
            },
            getList:function () {
                var el = this
                var paging = {
                    "current_page":el.current_page,
                    'num':el.num
                }
                var where = {}
                var title = ''
                var address = ''
                var tradeName = ''
                if(el.enterpriseName!=''){
                    title = el.enterpriseName
                }
                if(el.trade_id!=''){
                    where['member_category'] = el.trade_id
                }

                if(el.address!=''){
                    address = el.address
                }
                if(el.tradeChildName != ''){
                    tradeName = el.tradeChildName
                }
                var postData = {
                    "where":where,
                    "paging":paging,
                    'title':title,
                    'address':address,
                    'tradeName':tradeName

                }
                AjaxPost(postData,'/index/enterprise/getMemberPageWhere').then((response=>{
                    if(response.result.list){
                        el.list = response.result.list
                        el.pageInfo = response.result.pageInfo
                    }else{
                        el.list = []
                        el.pageInfo = {}
                    }
                    console.log(response)
                }))
            }
        },
        mounted(){
            this.$nextTick(function () {
                $('#distpicker').distpicker();
                this.getList()
                this.getTradeList()
            })
        }
    })
</script>